package com.ssy.lingxi.member.merchant.entity;

import com.fasterxml.jackson.annotation.JsonManagedReference;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;

/**
 * 会员等级（与关联的角色、权益）配置
 * @author 万宁
 * @version 2.0.0
 * @date 2020-07-04
 */
@Entity
@Table(schema = "public", name = "ms_mc_base_level_config", indexes = {@Index(name = "ms_mc_base_level_config_level_idx", columnList = "level"), @Index(name = "ms_mc_base_level_config_member_level_type_idx", columnList = "memberLevelTypeEnum"), @Index(name = "ms_mc_base_level_config_role_id_idx", columnList = "role_id")})
public class BaseLevelConfigDO implements Serializable {
    private static final long serialVersionUID = 2001085771908088934L;

    /**
     * 记录id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="base_level_config_seq")
    @SequenceGenerator(sequenceName="ms_mc_base_level_config_seq", name="base_level_config_seq",allocationSize = 1)
    private Long id;

    /**
     * 会员等级
     */
    @Column(columnDefinition = "int")
    private Integer level;

    /**
     * 等级标签
     */
    @Column(columnDefinition = "varchar(16)")
    private String levelTag;

    /**
     * 分值标签
     */
    @Column(columnDefinition = "varchar(16)")
    private String scoreTag;

    /**
     * 会员等级类型，定义在MemberLevelTypeEnum
     */
    @Column
    private Integer memberLevelTypeEnum;

    /**
     * 会员等级说明
     */
    @Column(columnDefinition = "varchar(80)")
    private String remark;

    /**
     * 角色名称（为了模糊查询冗余）
     */
    @Column(columnDefinition = "varchar(20)")
    private String roleName;

    /**
     * 状态 0-无效 1-有效
     */
    @Column(columnDefinition = "int2")
    private Integer status;

    /**
     * 一对一单向关联角色
     */
    @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "role_id", referencedColumnName = "id", foreignKey = @ForeignKey(name = "none",value = ConstraintMode.NO_CONSTRAINT))
    private RoleDO role;

    /**
     * 多对多单向关联会员权益
     */
    @JsonManagedReference
    @ManyToMany(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinTable(name="ms_mc_base_level_config_base_right_config_relation", joinColumns={ @JoinColumn(name="base_level_id", referencedColumnName="id")}, inverseJoinColumns={@JoinColumn(name="base_right_id", referencedColumnName="id")})
    private Set<BaseRightConfigDO> rights;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public String getLevelTag() {
        return levelTag;
    }

    public void setLevelTag(String levelTag) {
        this.levelTag = levelTag;
    }

    public String getScoreTag() {
        return scoreTag;
    }

    public void setScoreTag(String scoreTag) {
        this.scoreTag = scoreTag;
    }

    public Integer getMemberLevelTypeEnum() {
        return memberLevelTypeEnum;
    }

    public void setMemberLevelTypeEnum(Integer memberLevelTypeEnum) {
        this.memberLevelTypeEnum = memberLevelTypeEnum;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public RoleDO getRole() {
        return role;
    }

    public void setRole(RoleDO role) {
        this.role = role;
    }

    public Set<BaseRightConfigDO> getRights() {
        return rights;
    }

    public void setRights(Set<BaseRightConfigDO> rights) {
        this.rights = rights;
    }

}
